import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'
import type {
  GetLowCarbonMaterialListResult,
  PostCreateLowCarbonMaterialParams
} from './model/lowCarbonMaterialModel'

enum Api {
  /**
   * 分页查询低碳材料库列表
   */
  GET_LOW_CARBON_MATERIAL_LIST = '/footprint/factorMaterialRelation/pageRelation',
  /**
   * 不分页查询低碳材料库列表
   */
  GET_LOW_CARBON_MATERIAL_LIST_ALL = '/footprint/factorMaterialRelation/listRelation',
  /**
   * 创建低碳材料
   */
  POST_CREATE_RELATION = '/footprint/factorMaterialRelation/createRelation',
  /**
   * 编辑低碳材料（更换因子）
   */
  POST_EDIT_RELATION = '/footprint/factorMaterialRelation/editRelation',
  /**
   * 删除低碳材料
   */
  POST_DELETE_RELATION = '/footprint/factorMaterialRelation/deleteRelation',
  /**
   * 替换低碳材料
   */
  POST_REPLACE_MATERIAL = '/footprint/modelBom/replaceMaterial'
}

/**
 * 分页查询低碳材料库列表
 */
export const getLowCarbonMaterialList = (
  params: {
    materialName?: string
  } & BasicPagingListParams
): Promise<BasicPagingListResult<GetLowCarbonMaterialListResult>> =>
  get(Api.GET_LOW_CARBON_MATERIAL_LIST, params)

/**
 * 不分页查询低碳材料库列表
 */
export const getAllLowCarbonMaterialList = (): Promise<GetLowCarbonMaterialListResult[]> =>
  get(Api.GET_LOW_CARBON_MATERIAL_LIST_ALL)

/**
 * 创建低碳材料
 */
export const postCreateLowCarbonMaterial = (params: PostCreateLowCarbonMaterialParams) =>
  post(Api.POST_CREATE_RELATION, params)

/**
 * 编辑低碳材料
 */
export const postEditLowCarbonMaterial = (relationNo: string, factorNo: string) =>
  post(Api.POST_EDIT_RELATION, {
    relationNo,
    factorNo
  })

/**
 * 删除低碳材料
 */
export const postDeleteLowCarbonMaterial = (relationNo: string) =>
  post(Api.POST_DELETE_RELATION, { relationNo })

/**
 * 替换低碳材料
 */
export const postReplaceLowCarbonMaterial = (
  nodeNo: string,
  relationNo: string,
  materialName: string
) => post(Api.POST_REPLACE_MATERIAL, { nodeNo, relationNo, materialName })
